package com.itheima.controller;


import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
@Slf4j
public class ClazzController {
    @Autowired
    private ClazzService clazzService;


    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {

        PageResult pageResult = clazzService.page(clazzQueryParam);

        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        clazzService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Clazz clazz) {
        clazzService.save(clazz);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        clazzService.update(clazz);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list() {
      List<Clazz> clazzList = clazzService.findAll();
      return Result.success(clazzList);
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        System.out.println("根据ID查询, id=" + id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

}
